Class TKClass
The TKClass function will process a constructor function and set up its inheritance chain, synthetize a number of its instance properties and mix in additional capabilities based properties defined on that function. The supported properties are:
inherits– the superclassincludes– an Array of modules to pull insynthetizes– an Array of properties to synthetize
For instance, consider the following class declaration:
// extends MySuperClass
MyClass.inherits = MySuperClass;
// mixes in the TKEventTriage and TKPropertyTriage modules
MyClass.includes = [TKEventTriage, TKPropertyTriage];
// synthetizes the .foo and .bar properties
MyClass.synthetizes = ['foo', 'bar'];
function MyClass () {
// constructor code goes here
};
// process properties set up on the MyClass constructor
TKClass(MyClass);
Synthetization is fully automated as long as the class that wishes to offer synthetized properties follows the following rules:
- say the class wishes to synthetize the property
.foo - if the class chooses to define a getter method, it must be defined as
getFooon itsprototype - if the class chooses to define a setter method, it must be defined as
setFooon itsprototype - the class must define an instance variable
._foowhich is the internal object that the class is responsible to update if either a setter is specified
So our previous class declaration could be extended as follows:
function MyClass () {
this._foo = '';
};
// custom setter for .foo, the getter is not specified
// and TKClass() will automatically create it
MyClass.prototype.setFoo = function (newFooValue) {
this._foo = newFooValue;
};
// custom getter for .foo, the setter is not specified
// and TKClass() will automatically create it
MyClass.prototype.getBar = function (newFooValue) {
return 'Hello ' + this._foo;
};
Defined in: Class.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
TKClass(theClass)
|